import 'package:aegis_flutter_sdk/aegis_flutter_sdk.dart';
import 'package:aegis_flutter_sdk/src/pipes/repeat_limit.dart';
import 'package:flutter_test/flutter_test.dart';

import 'fakeAegis.dart';

void main() {
  FakeAegis aegis = FakeAegis(Config(id: 'test', repeat: 2));
  var repeatLimitFn = createErrorLogLimitPipe(aegis);
  group('repeat-limit-pipe', () {
    test('over-limit-error-log', () {
      List<NormalLog> logs = [
        NormalLog(msg: 'error', level: LogType.error),
        NormalLog(msg: 'error', level: LogType.error),
        NormalLog(msg: 'error', level: LogType.error),
      ];
      repeatLimitFn(logs, (res) {
        expect(res.length, 2);
      });
    });
    test('check if normal log pass succssfully', () {
      List<NormalLog> logs = [
        NormalLog(msg: 'info', level: LogType.info),
        NormalLog(msg: 'info', level: LogType.info),
        NormalLog(msg: 'info', level: LogType.error),
      ];
      repeatLimitFn(logs, (res) {
        expect(res.length, 3);
      });
    });
    // 检查下一次再上报同样的错误时，是否正确拦截
    test('next round error check', () {
      List<NormalLog> logs = [
        NormalLog(msg: 'error', level: LogType.error),
      ];
      repeatLimitFn(logs, (res) {
        expect(res.length, 0);
      });
    });
  });
}
